<?php
    
    /**
     * 管理员注册
    */
    include '../public/db_object.php';
   
    if(isset($_POST)){
        $login_name = trim($_POST['login_name']);
        $login_pwd = trim($_POST['login_pwd']);
        $sphone = trim($_POST['sphone']);
        $semail = trim($_POST['semail']);

        $db = new DB_object(["db_name"=>"db_shop"]);

        $sql_name = "select * from sys_user where login_name="."'$login_name'";
        $sql_sphone = "select * from sys_user where sphone="."'$sphone'";
        $sql_semail = "select * from sys_user where semail="."'$semail'";
        $l_name = $db->l_select_one($sql_name);
        // 判断是否重复用户名
        if(!empty($l_name)){
            echo 0; // 用户名已存在
            exit;
        }
        $l_sphone = $db->l_select_one($sql_sphone);
        if(!empty($l_sphone)){
            echo 2; //手机号已被注册
            exit;
        }
        $l_semail = $db->l_select_one($sql_semail);
        if(!empty($l_semail)){
            echo 3; //邮箱已被注册
            exit;
        }

        // 获取salt盐
        $str = "qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
        for($i=0; $i<26; $i++){
            @$ssalt .= substr(str_shuffle($str), mt_rand(0, strlen($str)-1), 1);
        }
        // 加密
        $newlogin_pwd = md5($login_pwd.$ssalt);
       
        $arr = ["null", "null", "'$sphone'", "'$semail'", "'$login_name'", "'$newlogin_pwd'", "'$ssalt'", "null"];
        // 插入表
        $res = $db->l_insert_one('sys_user', $arr);
        if($res){
            echo 1;
        }

    }

?>